package controller

import (
	"user-center/dto"
	"user-center/query"
	"user-center/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(SysDictController{
		sysDictService: service.NewSysDictService(),
	})
}

type SysDictController struct {
	sysDictService service.SysDictService
}

// 查询
// @Router [get] [/sysdict/:id]
func (m SysDictController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysDictService.Get(id)
}

// 增加
// @Router [post] [/sysdict]
func (m SysDictController) Save(c *gin.Context, dto *dto.SysDictDTO) any {
	dto.Id = ""
	return m.sysDictService.Save(dto)
}

// 修改
// @Router [put] [/sysdict/edit]
func (m SysDictController) UpdateById(c *gin.Context, dto *dto.SysDictDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysDictService.UpdateById(dto)

}

// 删除
// @Router [delete] [/sysdict/:id]
func (m SysDictController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysDictService.DeleteById(id)
}

// 查询列表
// @Router [post] [/sysdict/page]
func (m SysDictController) QueryPage(c *gin.Context, query *query.SysDictQueryDTO) any {
	return m.sysDictService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/sysdict/list]
func (m SysDictController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.sysDictService.QueryList(query)
}

// 分页下拉
// @Router [post] [/sysdict/getall]
func (m SysDictController) GetAll(c *gin.Context) any {
	return m.sysDictService.GetAll()
}
